package com.hehui.partimejob.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.hehui.partimejob.BaseActivity;
import com.hehui.partimejob.view.NavView;

public abstract class BaseFragment extends Fragment {
    public BaseActivity A;
    private NavView nav;
    public static String TAG;


    public NavView getNav() {
        return nav;
    }

    public void setNav(NavView nav) {
        this.nav = nav;
    }

    //    public MyNetwork N;
//    public LiveDataBus L;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        A = (BaseActivity) context;
//        N = MyNetwork.getInstance(context);
//        L = LiveDataBus.getInstance();
    }

    public <T extends View> T findViewById(int id) {
        return getView().findViewById(id);
    }

    public abstract void init();


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(getLayoutId(), container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        TAG = getClass().getSimpleName();
        ViewGroup root = (ViewGroup) getView();
        nav = new NavView();
        nav.createNavForFragment(root, this);
        init();
        begin(savedInstanceState);
    }

    protected abstract int getLayoutId();

    protected abstract void begin(Bundle bundle);
}
